<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<script src="${pageContext.request.contextPath}/dwz/js/dwz.database.js" type="text/javascript"></script>
<script type="text/javascript">
	function savedevIn() {
		var uuid = document.getElementsByName("orgLookupin.uuid");
		var list = {};
		var inNum = document.getElementsByName("innum");
		var schoolNames = document.getElementsByName("org.sclName");
		var inType=document.getElementById("inType").value;
		for (var j = 1; j < uuid.length; j++) {
			if (uuid[j].value == "") {
				alertMsg.error("请添加明细！");
				return false;
			}
			else{
				if (inNum[j].value == "") {
					alertMsg.error("入库数量不能为空！");
					inNum[j].focus();
					return false;
				}else{
					var reg = /^[0-9]*[1-9][0-9]*$/;
					if (!reg.test(inNum[j].value)) {
						alertMsg.error("必须输入大于0的正整数！");
						inNum[j].value = "";
						inNum[j].focus();
						return false;
					}
					}
				if(inType==""){
					alertMsg.error("请选择入库类型！");
					return false;
				}else if(inType=="2"){
					if(schoolNames[j].value==""||typeof(schoolNames[j].value)==undefined){
						alertMsg.error("还库必须选择学校！");
						return false;
					}
				}
				list[j-1] = inNum[j].value + "," + uuid[j].value+","+schoolNames[j].value;
		}
		}
		var describ = $("#describ").val();
		var userName = $("#userName").val();
		//var inType = $('input[name="inType"]:checked').val();
		var user=document.getElementsByName("userId");
		var userIds="";
		for(var k=1;k<user.length;k++){
			userIds=user[k].value;
		}
		var  url="stock_StockDevIn.action";
		data = {
			"dataList" : list,
			"stockDevin.describ" : describ,
			"stockDevin.inputer" : userName,
			"stockDevin.inType" : inType,
			"stockDevin.inputId" : userIds
		}, $.ajax({
			url : url,
			type : "post",
			data : data,
			dataType : "json",
			success : function(message) {
				if (message != "") {
					alertMsg.correct("入库申请成功！");
					$("#cwsList").empty();
				}
			}
		});
	}
	function addWin() {
		var _box = $("table.itemDetail").initUI();
		var $p = $(_box || document);
		$("table.itemDetail", $p).itemDetail();
	}
	function in_type_change(){
		var inType=$("#inType").val();
		//var scLClick=document.getElementsById("href_org.sclName");//dwz.database.js中添加了类型为lookup1的查找带回类型，按钮名字在其中定义，name格式为href_回显框名字
		if(inType=="1"){
			$("#cwsList").html(""); 
		}else if(inType=="2"){
			$("#cwsList").html(""); 

		}
	}
	function selScl(){
		var inType=$("#inType").val();
		
		if(inType=="1"){
			alertMsg.error("采购入库无需选择学校！");
			return;
		}else{
			return;
		}
		
	}
</script>
<style>
<!--
.searchContent td label {
	width: 50px;
}
-->
</style>
<%--dwz分页查询 隐藏传值表单  begin --%>
<form id="pagerForm" method="post" action="#rel#">
	<input type="hidden" name="pageNum" value="${currentPage }" /> <input
		type="hidden" name="numPerPage" value="${numPerPage}" /> <input
		type="hidden" name="orderField" value="${param.orderField}" /> <input
		type="hidden" name="orderDirection" value="${param.orderDirection}" />
</form>
<%--dwz分页查询 隐藏传值表单  end --%>
<%--页头 检索条件区域 begin --%>
<div class="pageHeader">
	<form rel="pagerForm" onsubmit="return navTabSearch(this);"
		action="stock_listStockDev.action" method="post">
		<div class="searchBar">
			<table class="searchContent" id="tab">
				<tr>
					<td>申请人：</td>
					<td><input value="${session.currentUser.userRole.usrName }"
						id="userName" type="text" readonly="readonly" /> <input value="${session.currentUser.userRole.usrId }"
						id="userId" name="userId" type="hidden" /> <!-- 登陆工号 --></td>
					<!-- <td><input type="radio" value="1" name="inType"
						checked="checked" />采购 &nbsp;&nbsp;&nbsp; <input type="radio"
						value="2" name="inType" />还库</td> -->
					<td>入库类型：<select id="inType" name="inType" onchange="in_type_change();">
									<option value="">--请选择--</option>
									<option  value="1">采购</option>
									<option value="2">还库</option>
								</select></td>
				</tr>
				<tr>
					<td>备注：</td>
					<td colspan="2"><textarea rows="2" cols="30" id="describ"></textarea>

					</td>
				</tr>
			</table>
		</div>
	</form>
</div>
<%--页头 检索条件区域 end --%>
<%--内容展示区域 begin --%>
<div class="pageContent">
	<%-- 工具栏  begin --%>
	<div class="panelBar">
		<ul class="toolBar">
			<li >
				<a id="link_stockdevice_in" class="add" href="javascript:void(0)" onclick=""><span>新建入库单</span></a>
				<input type="hidden" id="db_btn_link_id" value="link_stockdevice_in">
			</li>
			<li><a class="add" href="javascript:void(0)" onclick="savedevIn()"><span>提交申请</span></a></li>
		</ul>

	</div>
	<%-- 工具栏 end  --%>

	<table id="tab" class="list nowrap itemDetail"  addButton="新建入库单" width="100%">
		<thead id="inList">
			<tr id="tr">
				<th type="readonly" id="uuid" name="orgLookupin.uuid"
					suggestFields="orgNum,uuid">序列号</th>
				<th type="readonly" id="devName" name="orgLookupin.devName" value=""
					suggestFields="orgNum,orgName">设备名称</th>
				<th type="readonly" id="devUnit" name="orgLookupin.devUnit" value=""
					suggestFields="orgNum,devUnit">设备单位</th>
				<th type="text" name="innum" id="innum">设备数量</th>
				<th type="readonly" id="devVer" name="orgLookupin.devVer" value=""
					suggestFields="orgNum,devVer">设备版本</th>
				<th type="readonly" id="devSupplierName" name="orgLookupin.devSupplierName" value=""
					suggestFields="orgNum,devUnit">设备供应商</th>
				<th type="readonly" id="describe" name="orgLookupin.describe" value=""
					suggestFields="orgNum,describe">设备描述</th>
				<th type="lookup1" name="org.sclName" lookupGroup="org"  id="scl"
					lookupUrl="school_lookup.action" 
					suggestFields="orgNum,sclName" postField="keywords" size="12" >退还学校（还库时选择）</th>
				<th type="lookup" name="items[#index#].org.orgName"
					lookupGroup="orgLookupin" lookupUrl="stock_stockDicTabUi.action">选择设备</th>
				<th type="del" width="60">操作</th>

			</tr>
		</thead>
		<tbody id="cwsList"></tbody>
	</table>
	<%-- 分页table列表 begin --%>

	<%-- 分页table列表 end --%>

	<%--分页信息区 begin--%>
	<%--分页信息区 end--%>
</div>